#include "comm.hpp"

int main()
{
  umask(0);
  //创建命名管道
  int ret = mkfifo(fileName.c_str(), mode);
  if(ret == -1)
  {
    std::cout << errno << " : " << strerror(errno) << std::endl;
    exit(-1);
  }
  //打开命名管道
  int fd = open(fileName.c_str(), O_WRONLY);
  if(fd < 0)
  {
    std::cout << errno << " : " << strerror(errno) << std::endl;
    exit(-1);
  }
  //开始写入
  char buffer[NUM] = "i am process A";
  int cnt = 5;
  while(cnt)
  {
    std::cout << "这是我发的第 " << cnt << " 条消息" << std::endl;
    int n = write(fd, buffer, sizeof(buffer) - 1);
    if(n < 0)
    {
      std::cout << errno << " : " << strerror(errno) << std::endl;
      exit(-1);
    }
    cnt--;
    sleep(1);
  }
  close(fd);
  unlink(fileName.c_str());
  return 0;
}
